<?php

namespace App\Service\User\v1_2_8;

// use App\Constants\ErrorCode;

use App\Model\Guild\GuildHost;
use App\Model\UserProfile;
use App\Service\User\UserBaseService;

/**
 * 邀请绑定信息
 */
class InviteBindInfoService extends UserBaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        // $inviteCode = $this->request->input('invite_code', '');
        //限制用户注册时间
        $lmtMinutes = config('act.invite.bind_expire');
        $selfProfile = UserProfile::getProfile($userId);
        $regTime = strtotime((string)$selfProfile->created_at);
        $expTime = $regTime + $lmtMinutes * 60;
        //主播检测工会绑定
        $inviteCode = $selfProfile->invite_code;
        if (UserProfile::checkRoleHost($selfProfile->role)) {
            $guildHost = GuildHost::checkInGuild($userId, 'data');
            if ($guildHost && $guildHost->guildInfo) $inviteCode = $guildHost->guildInfo->guild_id;
        }
        $validHour = floor($lmtMinutes / 60);
        return [
            'invite_code' => $inviteCode,
//            'expired' => $expTime <= time() ? 1 : 0,
            'expired' => 1,
            'expired_text' => "邀请人绑定仅注册{$validHour}小时内绑定有效；\n截止绑定时间：" . date('Y-m-d H:i:s', $expTime),
            'rules' => "在邀请人主页找到ta的专属ID（一般为52或53开头的数字），{$validHour}小时内填写邀请人ID并提交成功则绑定成功；\n邀请人必须为已注册过的用户，不能绑定自己哦～"
        ];
    }
}
